import socket
import select

server = socket.socket()
server_address = ("127.0.0.1", 8000)
server.bind(server_address)
server.listen(10)
print("服务器启动成功，监听IP：", server_address)

epoll = select.epoll()
epoll.register(server.fileno(), select.EPOLLIN)

while True:
    print("等待活动连接......")
    events = epoll.poll(10)

    if not events:
        print("epoll超时无活动连接，重新轮询......")
        continue

    print("有", len(events), "个新事件，开始处理......")
    for fd, event in events:
        connection, address = server.accept()
        connection.setblocking(False)
        epoll.register(connection.fileno(), select.EPOLLIN)

epoll.unregister(server.fileno())
epoll.close()
server.close()
